﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;

namespace SharpMap.Wpf.Rendering
{
    public class GeometryVisual : GeoVisual
    {
        StreamGeometry _path = null;
        public StreamGeometry Path
        {
            get { return _path; }
            set {  _path = value;  }
        }

        public override Rect Bounds
        {
            get { return Path.Bounds; }
        }

         public override void SetStyle(SharpMap.Styles.IStyle style,SharpMap.Rendering.RenderState state)
        {
            SharpMap.Styles.VectorStyle vStyle = ( SharpMap.Styles.VectorStyle)style;
            //Style.Set(vStyle,state);
        }


        public override void Render(WpfStyleHolder style)
        {
            PathGeometryStyleHolder ngStyle = (PathGeometryStyleHolder)style;
            RenderInternal(ngStyle);
        }

        /// <summary>
        /// //TODO: Remember to check if Enabled Outline before calling
        /// </summary>
        /// <param name="renderedDrawings"></param>
        /// <param name="line"></param>
        /// <param name="outline"></param>
        /// <param name="fill"></param>
        private void RenderInternal(PathGeometryStyleHolder style)
        {
            if (_path != null)
            {
                
                using (DrawingContext ctx = this.RenderOpen())
                {
                    Geometry g = _path;

                    if (style.Line != null)
                    {
                        ctx.DrawGeometry(null, style.NormlizedLine, g);
                    }
                    if (style.Fill != null)
                    {
                        ctx.DrawGeometry(style.Fill, null, g);
                    }
                    if (style.Outline != null)
                    {
                        ctx.DrawGeometry(null, style.NormalizedOutline, g);
                    }
                }
            }
        }
    }
}
